<?php
	$obj = new Post();
	$type=$_GET['type'];
	$objMenu=new Menu();
	$objMenu->loadByKey($type);
	if ( strcasecmp( @ $_SERVER['REQUEST_METHOD'], 'POST' ) == 0 )
	{
		//print_r($_POST['delete']);
		$arr=$_POST['delete'];
		if(count($arr))
		{
			$s=arrToList($arr,",");
			foreach($arr as $key => $val)
			{
				$obj->PostID=$val;
				$obj->delete($conn);
			}
		}
		//linkto("?module=$module");	
	}
?>
<form name="f" action="" method="post" enctype="multipart/form-data">
<div class="ContentTitle">
    <div class="left" style="padding-top:8px"><?php echo $objMenu->MenuName?></div>
    <div class="CMSButton right">
		<a href="?">Về trang chủ</a>
        <?php
		if($objUserType->isAllow($objModule->ModuleID,1)!=-1 )
		{
		?>
		<a href="?module=<?php echo $module?>&action=get&cid=<?php echo $type?>">Thêm</a>
		<?php
		}
		?>
        <?php
        if($objUserType->isAllow($objModule->ModuleID,2)!=-1)
		{
		?>
                <a href="#" onclick="fsubmit()">Xóa</a>
		<?php
		}
		?>
    </div>    
    <div class="clear"></div>
</div>
<ul id="ContentTabs" class="shadetabs">
    <!--
    <li><a class="selected" onclick="ShowHideDiv('Tab',1,2)">General Information</a></li>
    <li><a onclick="ShowHideDiv('Tab',1,2)">Account Information</a></li>
    -->
</ul>       

<div id="Tab1" class="TabContainer" style="display:block">
<!-------------CONTENT OF EACH MODULE ---------------------------->
<table width="100%">
	<tr valign="top">
        <td>
        	<table width="100%" class="list">
                <thead>
                  <tr class="thead">
                      <td class="tdright" width="33">
                      <input type="checkbox" onclick="$('input[name*=\'delete\']').attr('checked', this.checked);"/>
                      </td>
                      
                      <td class="tdleft">Tiêu đề</td>
                      <td class="tdleft">Tóm tắt</td>
                      <td class="tdleft">Hình</td>
                      <td class="tdcenter" width="100"></td>
                  </tr>
                </thead>
                <tbody>
			<?php
                $where=" WHERE 1=1 ";
                $where.=" AND NewsTypeID = '$type' ORDER BY `PostID` DESC";
                $obj=new Post();
                $data=array();
                $data=$obj->travel($where);
                
                
                /*******Start Paging*****************************/
                $page = $_GET['page'];			
                $limit = 20; 
                $total = count($data); 
                // work out the pager values 
                $pager  = Pager::getPagerData($total, $limit, $page); 
                $offset = $pager->offset; 
                $limit  = $pager->limit; 
                $page   = $pager->page;
                /*******Break paging*******************************/
                for($i=$offset;$i<$offset+$limit && $data[$i]!="";$i++)
                {
                    $obj->loadByKey($data[$i]);
                    $class="even";
                    if($i%2!=0)
                        $class="odd";
            ?>
                    <tr class="<?php echo $class?>"  >
                        <td class="tdright">
                        <input type="checkbox" name="delete[<?php echo $i?>]" value="<?php echo $obj->PostID?>"/>
                        </td>
                        
                        <td class="tdleft"><?php echo $obj->Title?></td>
                        <td class="tdleft"><?php echo html_entity_decode( $obj->Summary)?></td>
                       	<td class="tdleft"><img id="preview" src="<?php echo $img->resizePNG($obj->ImagePath,100,100)?>" /></td>
                        <td class="tdcenter">
            <?php
                    if($objUserType->isAllow($objModule->ModuleID,3)!=-1 && $objMenu->ModuleID !="rss")
                    {
            ?>
                            [<a class="buttonlink" href="?module=<?php echo $module?>&action=get&cid=<?php echo $obj->NewsTypeID?>&id=<?php echo $obj->PostID?>">Chỉnh sửa</a>]
            <?php
                    }
            ?>
            
                        </td>
                    </tr>
            <?php
                }
            ?>
                    
                </tbody>
            </table>
        </td>
    </tr>
</table>


<?php
	include("modules/page.php");
?>
<!-------------END CONTENT OF EACH MODULE ---------------------------->
</div>
</form>
<script language="javascript">
from=document.f
function fsubmit()
{
	anser=confirm('Are you sure delete !')
	if(anser==true)
	{
		from.submit()
	}
}
</script>